package net.hn.hnms.biz.emgcy.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.emgcy.domain.AllocationRecordPo;
import net.hn.hnms.biz.emgcy.domain.dto.AllocationRecordDto;
import net.hn.hnms.biz.emgcy.domain.vo.AllocationRecordVo;
import net.hn.hnms.biz.emgcy.service.AllocationRecordService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: baijiajun
 * @Date: 2022/9/13
 */
@Api(value = "调拨记录模块", tags = {"调拨记录"})
@RestController
@RequestMapping("alloctionRecord")
public class AllocationRecordController {
    @Resource
    private AllocationRecordService allocationRecordService;

    @ApiOperation("调拨记录列表")
    @GetMapping("pageList")
    @AutoSetMineCode
    public R<ResponsePage<AllocationRecordVo>> pageList(PageQuery pageQuery, AllocationRecordDto allocationRecordDto) {
        ResponsePage<AllocationRecordVo> list=allocationRecordService.pageList(pageQuery,allocationRecordDto);
        return R.ok(list);
    }

    @ApiOperation("调拨添加")
    @PostMapping("/add")
    public R add(@RequestBody AllocationRecordPo allocationRecordPo){
        List<Object> allocationObject = allocationRecordPo.getAllocationObj();
        String str="";
        for(Object obj:allocationObject){
            str+=obj+",";
        }
        allocationRecordPo.setAllocationObject(str.substring(0,str.length()-1));
        Boolean flag = allocationRecordService.add(allocationRecordPo);
        if(flag){
            return R.ok("新增成功");
        }
        return R.fail("新增失败");
    }

    @ApiOperation("调拨修改")
    @PutMapping("/update")
    public R update(@RequestBody AllocationRecordPo allocationRecordPo){
        Boolean flag = allocationRecordService.update(allocationRecordPo);
        if(flag){
            return R.ok("修改成功");
        }
        return R.fail("修改失败");
    }
    @ApiOperation("调拨删除")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long  id){
        Boolean flag = allocationRecordService.delete(id);
        if(flag){
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
}
